package com.example.recyclerview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class MyAdaper extends RecyclerView.Adapter<MyAdaper.MyHodler>{
    private List<RecyBean> list;
    private Context context;


    public void setList(List<RecyBean> list) {
        this.list = list;
    }

    public MyAdaper(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public MyHodler onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {
        return new MyHodler(LayoutInflater.from(context).inflate(R.layout.recy_item_layout,null));
    }

    @Override
    public void onBindViewHolder(@NonNull MyAdaper.MyHodler holder, int position) {
        holder.recyname.setText(list.get(position).getRecyname());
        holder.recyid.setImageResource(list.get(position).getRecyid());
    }

    @Override
    public int getItemCount() {
        return null!=list?list.size():0;
    }

    class MyHodler extends RecyclerView.ViewHolder {
        ImageView recyid;
        TextView recyname;

        public MyHodler(@NonNull  View itemView) {
            super(itemView);
            recyid=itemView.findViewById(R.id.img_wu);
            recyname=itemView.findViewById(R.id.text_wu);
        }
    }
}
